from flask_wtf import FlaskForm
from wtforms import StringField, SelectField, widgets, DecimalField, FloatField, BooleanField
from flask_ckeditor import CKEditorField
from wtforms.validators import DataRequired, Length


class GoodsAddForm(FlaskForm):
    name = StringField(label='商品名称', validators=[DataRequired(message='请输入商品名称'),
                                                     Length(1, 30, message='商品名称长度在1-30个字符之间')],
                       render_kw={'class': 'form-control', 'placeholder': '请输入商品名称'})
    category_id = StringField(label='商品分类', validators=[DataRequired(message='请选择商品分类')],
                              render_kw={'class': 'form-control custom-select', 'placeholder': '请选择商品分类'})
    market_price = DecimalField(label='市场价', validators=[DataRequired(message='请输入商品市场价')],
                                render_kw={'class': 'form-control', 'placeholder': '请输入商品市场价'})
    price = DecimalField(label='销售价', validators=[DataRequired(message='请输入销售价')],
                         render_kw={'class': 'form-control', 'placeholder': '请输入销售价'})
    main_img = StringField(label='商品主图', widget=widgets.FileInput(),
                          render_kw={'class': 'custom-file-input'})
    goods_desc = CKEditorField(label='商品描述', validators=[DataRequired(message='请输入商品描述')],
                              render_kw={'class': 'form-control'})
    unit = StringField(label='商品单位',
                     render_kw={'class': 'form-control'})
    status = SelectField(label='商品状态', coerce=int,
                         choices=[(1, '正常'), (0, '下架')],
                         render_kw={'class': 'form-control custom select', 'placeholder': '请选择商品状态'})
    is_recommend = BooleanField(label='是否推荐', render_kw={'class': 'form-control'})


class GoodsEditForm(FlaskForm):
    name = StringField(label='商品名称', validators=[DataRequired(message='请输入商品名称'),
                                                     Length(1, 30, message='商品名称长度在1-30个字符之间')],
                       render_kw={'class': 'form-control', 'placeholder': '请输入商品名称'})
    category_id = StringField(label='商品分类', validators=[DataRequired(message='请选择商品分类')],
                              render_kw={'class': 'form-control custom-select', 'placeholder': '请选择商品分类'})
    market_price = DecimalField(label='市场价', validators=[DataRequired(message='请输入商品市场价')],
                                render_kw={'class': 'form-control', 'placeholder': '请输入商品市场价'})
    price = DecimalField(label='销售价', validators=[DataRequired(message='请输入销售价')],
                         render_kw={'class': 'form-control', 'placeholder': '请输入销售价'})
    main_img = StringField(label='商品主图', widget=widgets.FileInput(),
                           render_kw={'class': 'custom-file-input'})
    goods_desc = CKEditorField(label='商品描述', validators=[DataRequired(message='请输入商品描述')],
                               render_kw={'class': 'form-control'})
    unit = StringField(label='商品单位',
                       render_kw={'class': 'form-control'})
    status = SelectField(label='商品状态', coerce=int, choices=[(1, '正常'), (0, '下架')],
                        render_kw={'class': 'form-control custom select', 'placeholder': '请选择商品状态'})
    is_recommend = BooleanField(label='是否推荐', render_kw={'class': 'form-control'})